$(()=>{
    $("#uploadBtn").click(() => {
        let formData = new FormData($("#upload")[0]);
        $("#main").addClass("el-loading");
        $.ajax({
            type: 'post',
            url: url,
            data: formData,
            cache: false,
            processData: false,
            contentType: false,
            success: data => {
                $("#avatar").attr("src", data);
                $("#main").removeClass("el-loading");
                dialog("提示","头像上传成功");
                console.log(data);
            },
            error: () => {
                $("#main").removeClass("el-loading");
                dialog("错误","上传失败");
            }
        });
    });
    $("#avatar").focus();
    
    $("#btn").click(()=>{
        $("#first").addClass("el-loading");
        let avatar=$("#avatar").attr("src");
        $.post("{LINK_user/info/avatar/set}",{
            avatar:avatar
        },text=>{
            $("#first").removeClass("el-loading");
            let data=JSON.parse(text);
            if(data.status){
                dialog("提示","头像修改成功，即将回到用户中心");
                setTimeout(() => {
                    location.href="{LINK_user#info}";
                }, 1000);
            }else{
                dialog("错误","头像修改失败："+data.msg);
            }
        });
    });
});